package application.common.ui;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class AuthorizeDialog {

	public MediaPlayer player;
	public Stage mainStage;
	public String message;
	public int messageType=0;
	public double width=400;
	public double height=250;
	private final Stage stage = new Stage();	
	private Button sureBtn;
	private Button closeBtn;
	private PasswordField passwordField;
	private Label messageLabel;
	public AuthorizeDialog(Stage mainStage) {
		this.mainStage = mainStage;
		initGUI();
	}
	
	public void initGUI(){
		
		stage.initOwner(mainStage);
		stage.initModality(Modality.WINDOW_MODAL);
		
		stage.setWidth(width);
		stage.setHeight(height);
		stage.initStyle(StageStyle.UNDECORATED);
		
		Pane pane=new Pane();
		pane.setPrefSize(width, height);
		pane.setId("layer");
		
		ImageView iconView=new ImageView();
		iconView.setFitHeight(60.0);
		iconView.setFitWidth(60.0);
		iconView.setLayoutX(170.0);
		iconView.setLayoutY(30.0);
		iconView.setImage(new Image(getClass().getResourceAsStream("/application/resources/icon-pwd.png")));
		
		passwordField=new PasswordField();
		passwordField.setPrefSize(250, 46);
		passwordField.setLayoutX(75);
		passwordField.setLayoutY(108);
		passwordField.setTooltip(new Tooltip("请输入密码") );
		passwordField.setId("layer-label");
		
		
		messageLabel=new Label();
		messageLabel.setLayoutX(32.0);
		messageLabel.setLayoutY(152.0);
		messageLabel.setPrefSize(336.0, 50.0);
		messageLabel.setText(this.message);
		messageLabel.setText("请输入维护密码！");
		messageLabel.setId("layer-label");
		
		sureBtn=new Button();
		sureBtn.setLayoutX(204.0);
		sureBtn.setLayoutY(200.0);
		sureBtn.setText("确定");
		sureBtn.setPrefSize(80.0, 26);
		sureBtn.setId("layer-btn");
		
		closeBtn=new Button();
		closeBtn.setLayoutX(104.0);
		closeBtn.setLayoutY(200.0);
		closeBtn.setText("关闭");
		closeBtn.setPrefSize(80.0, 26);
		closeBtn.setId("layer-btn");
		closeBtn.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				close();
			}
		});
		
		pane.getChildren().add(passwordField);
		pane.getChildren().add(iconView);
		pane.getChildren().add(messageLabel);
		pane.getChildren().add(sureBtn);
		pane.getChildren().add(closeBtn);

		Scene scene = new Scene(pane, width, height);
		scene.getStylesheets().add(getClass().getResource("/application/application.css").toExternalForm());
		stage.setScene(scene);
		stage.show();
	}
	
	public void addListner(EventHandler<ActionEvent> actionEvent) {
		sureBtn.setOnAction(actionEvent);
	}
	
	public void addCloseListner(EventHandler<ActionEvent> actionEvent) {
		closeBtn.setOnAction(actionEvent);
	}
	
	public String getPassword() {
		return  passwordField.getText();
	}
	
	public void setMsg(String value) {
		messageLabel.setText(value);
	}
	
	
	public void close() {
		stage.close();
	}
}
